package com.ruoyi.web.controller.equipment;

import java.util.List;

import com.ruoyi.equipment.domain.FzEquipmentKey;
import com.ruoyi.equipment.service.IFzEquipmentKeyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备钥匙Controller
 * 
 * @author ruoyi
 * @date 2020-03-22
 */
@Controller
@RequestMapping("/equipment/key")
public class FzEquipmentKeyController extends BaseController
{
    private String prefix = "equipment/key";

    @Autowired
    private IFzEquipmentKeyService fzEquipmentKeyService;

    @RequiresPermissions("equipment:key:view")
    @GetMapping()
    public String key()
    {
        return prefix + "/key";
    }

    /**
     * 查询设备钥匙列表
     */
    @RequiresPermissions("equipment:key:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FzEquipmentKey fzEquipmentKey)
    {
        startPage();
        List<FzEquipmentKey> list = fzEquipmentKeyService.selectFzEquipmentKeyList(fzEquipmentKey);
        return getDataTable(list);
    }

    /**
     * 导出设备钥匙列表
     */
    @RequiresPermissions("equipment:key:export")
    @Log(title = "设备钥匙", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzEquipmentKey fzEquipmentKey)
    {
        List<FzEquipmentKey> list = fzEquipmentKeyService.selectFzEquipmentKeyList(fzEquipmentKey);
        ExcelUtil<FzEquipmentKey> util = new ExcelUtil<FzEquipmentKey>(FzEquipmentKey.class);
        return util.exportExcel(list, "key");
    }

    /**
     * 新增设备钥匙
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备钥匙
     */
    @RequiresPermissions("equipment:key:add")
    @Log(title = "设备钥匙", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzEquipmentKey fzEquipmentKey)
    {
        return toAjax(fzEquipmentKeyService.insertFzEquipmentKey(fzEquipmentKey));
    }

    /**
     * 修改设备钥匙
     */
    @GetMapping("/edit/{keyId}")
    public String edit(@PathVariable("keyId") String keyId, ModelMap mmap)
    {
        FzEquipmentKey fzEquipmentKey = fzEquipmentKeyService.selectFzEquipmentKeyById(keyId);
        mmap.put("fzEquipmentKey", fzEquipmentKey);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备钥匙
     */
    @RequiresPermissions("equipment:key:edit")
    @Log(title = "设备钥匙", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzEquipmentKey fzEquipmentKey)
    {
        return toAjax(fzEquipmentKeyService.updateFzEquipmentKey(fzEquipmentKey));
    }

    /**
     * 删除设备钥匙
     */
    @RequiresPermissions("equipment:key:remove")
    @Log(title = "设备钥匙", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzEquipmentKeyService.deleteFzEquipmentKeyByIds(ids));
    }
}
